package com.fangda.network.tcp.client;

import com.fangda.network.NetworkConfig;
import com.fangda.network.NetworkProvider;
import io.vertx.core.Vertx;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetClientOptions;

public class TcpClientProvider implements NetworkProvider<TcpClientNetwork> {

    @Override
    public TcpClientNetwork createNetwork(Vertx vertx, String id, NetworkConfig networkConfig) {
        NetClientOptions config = (NetClientOptions)networkConfig.getConfig().getOrDefault("options", new NetClientOptions());
        NetClient client = vertx.createNetClient(config);
        TcpClientNetwork network = new TcpClientNetwork(id, networkConfig);
        network.setClient(client);
        return network;
    }
}
